package com.hong.utils.executors;

import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @Auther: Administrator
 * @Date: 2018/7/26 18:09
 * @Description:
 */
public class ThreadPoolExecutorTask {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = new ThreadPoolExecutor(10,20,30,TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10), r -> {
            Thread t = new Thread(r);
            return t;
        },new ThreadPoolExecutor.AbortPolicy());

        IntStream.range(0,20).boxed().forEach(i->{
            executorService.execute(()->{
                try {
                    TimeUnit.SECONDS.sleep(10);
                    System.out.println(Thread.currentThread().getName()+"["+i+"] finish done.");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        });
        List<Runnable> runnableList = null;
        try {
            runnableList = executorService.shutdownNow();
            System.out.println("==============================");
        }catch (Exception e){
            e.printStackTrace();
        }
/*        executorService.shutdown();
        executorService.awaitTermination(1,TimeUnit.HOURS);*/
        System.out.println("==============over=================");
        System.out.println(runnableList);
        System.out.println(runnableList.size());
    }
}
